/*
 * Plotter.cpp
 *
 *  Created on: 27/07/2011
 *      Author: godinho
 */

#include "Plotter.h"

Plotter::Plotter() {
	mAxis = new AxisPainter();

	mColors.push_back(QColor(0x00, 0x00, 0xff));
	mColors.push_back(QColor(0xff, 0x00, 0x00));
	mColors.push_back(QColor(0xff, 0x00, 0xff));
	mColors.push_back(QColor(0xff, 0xff, 0x00));
	mColors.push_back(QColor(0x00, 0x00, 0x00));
	mColors.push_back(QColor(0x00, 0x00, 0x00));
}

Plotter::~Plotter() {
	delete mAxis;
}

void Plotter::plot(QPainter* painter, QRect bounds, CategoryDataSet* dataset) {

	mAxis->paint(painter, bounds, 20, 1);

	float p1y, p1x, p2y, p2x;

	p1y = p1x = 3;
	p2y = p2x = 4;

	for(int i = 0; i < dataset->getSerieCount(); i++) {
		QPen pen = QPen(mColors[i%mColors.size()]);
		painter->setPen(pen);
		drawSerie(painter, bounds, dataset->getSerie(i));
	}
}

void Plotter::drawSerie(QPainter* painter, QRect bounds, Serie* s) {

	for(int i = 0; i < s->valuesCount()-1; i++) {
		QLine line = QLine(mAxis->getPoint(s->getCol(i), s->getRow(i)),
						   mAxis->getPoint(s->getCol(i+1), s->getRow(i+1)));

		painter->drawLine(line);
	}
}

void Plotter::drawPoint(QPainter* painter, double x, double y) {

}

